import request from '@/utils/requset'

export const getCheckInroService = () => {
  return request.get('/member/order/pre')
}

type OrderParams = {
  receiver: string
  contact: string
  provinceCode: string
  cityCode: string
  countyCode: string
  address: string
  postalCode: string
  addressTags: string
  isDefault: boolean
  fullLocation: string
}
export const getAddressListService = () => {
  return request.get('/member/address')
}
export const addAddressService = ({
  receiver,
  contact,
  provinceCode,
  cityCode,
  countyCode,
  address,
  postalCode,
  addressTags,
  isDefault,
  fullLocation
}: OrderParams) => {
  return request.post('/member/address', {
    receiver,
    contact,
    provinceCode,
    cityCode,
    countyCode,
    address,
    postalCode,
    addressTags,
    isDefault: isDefault ? 0 : 1,
    fullLocation
  })
}

export const delAddressService = (id: string) => {
  return request.delete(`/member/address/${id}`)
}

export const createOrderService = (data: any) => {
  return request.post('/member/order', data)
}
export const getOrderListService = (id: string) => {
  return request.get(`/member/order/${id}`)
}

export const updateAddressService = (data: any) => {
  //将data中的isDefault转换为0或1
  data.isDefault = data.isDefault ? 0 : 1
  return request.put(`/member/address/${data.id}`, data)
}
